package com.xtayfjpk.zookeeper.test.master_workers.watcher;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;

import com.xtayfjpk.zookeeper.test.master_workers.Worker;

public class NewTaskWatcher implements Watcher {
	private Worker worker;
	
	public NewTaskWatcher(Worker worker) {
		this.worker = worker;
	}
	
	@Override
	public void process(WatchedEvent e) {
		if(e.getType() == EventType.NodeChildrenChanged) {
            assert new String("/assign/worker-"+ worker.getServerId() ).equals( e.getPath() );
            
            worker.monitorTasks();
        }
	}

}
